package com.pignest.hotel.servlet.report;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import com.pignest.framework.util.Utils;
import com.pignest.hotel.beans.report.CheckoutSummary;
import com.pignest.hotel.definition.InComeItemType;
import com.pignest.hotel.definition.PayMethod;
import com.pignest.hotel.service.ReportService;
import com.pignest.hotel.spring.Services;

public class CheckoutSummaryReport extends BaseReport {
	
	@Override
	public void initParameters(HttpServletRequest req) {
		super.initParameters(req);
		notNull(startTime);
		if (endTime == null)
			endTime = new Date();
	}

	@Override
	public Map<String, Object> getParameters(HttpServletRequest req) {
		Map<String, Object> params = new HashMap<String, Object>();
		ReportService service = Services.getReportService();
		CheckoutSummary summary = service.reportCheckoutSummary(startTime, endTime);
		params.put("amount01", toPrice(summary.getConsume(InComeItemType.FF) + summary.getConsume(InComeItemType.FJTZF) + summary.getConsume(InComeItemType.JSFF)));
		params.put("amount02", toPrice(summary.getConsume(InComeItemType.WPXF)));
		params.put("amount03", toPrice(summary.getConsume(InComeItemType.QXF)));
		params.put("amount04", toPrice(summary.getConsume(InComeItemType.PCF)));
		params.put("amount05", toPrice(summary.getConsume(InComeItemType.YJ) + summary.getConsume(InComeItemType.XCK)));
		params.put("amount06", toPrice(summary.getTotalConsumption()));
		
		params.put("amount07", toPrice(summary.getPayment(PayMethod.CASH)));
		params.put("amount08", toPrice(summary.getPayment(PayMethod.MEMBER_CARD)));
		params.put("amount09", toPrice(summary.getPayment(PayMethod.DEBIT_CARD)));
		params.put("amount10", toPrice(summary.getPayment(PayMethod.CREDIT_CARD)));
		params.put("amount11", toPrice(summary.getTotalPayment()));
		return params;
	}
	
	private String toPrice(long v) {
		return Utils.toPrice(Math.abs(v));
	}

	@Override
	public String getReportName() {
		return "结账汇总表";
	}

}
